//
//  SettingUtils.m
//  PStoneSDKDemo
//
//  Created by 元潮 谢 on 16/10/8.
//  Copyright © 2016年 元潮 谢. All rights reserved.
//

#import "SettingUtils.h"

#define DateFormateStringDefault @"yyyy-MM-dd HH:mm:ss"

@implementation SettingUtils

+(void)setAESKey:(NSString*)object lockName:(NSString*)lockName
{
    
    [[NSUserDefaults standardUserDefaults] setValue:object forKey:[NSString stringWithFormat:@"aes_key_%@",lockName]];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(NSString*)getAESKeylockName:(NSString*)lockName
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString * value = [defaults stringForKey:[NSString stringWithFormat:@"aes_key_%@",lockName]];
    return value;
}


+(void)setAccount:(NSString*)object
{
    
    [[NSUserDefaults standardUserDefaults] setValue:object forKey:@"setting_account"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(NSString*)getAccount
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString * value = [defaults stringForKey:@"setting_account"];
    return value;
}


+(void)setPassword:(NSString*)object
{
    
    [[NSUserDefaults standardUserDefaults] setValue:object forKey:@"setting_password"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(NSString*)getPassword
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString * value = [defaults stringForKey:@"setting_password"];
    return value;
}


+(void)setSignUp:(BOOL)object
{
    
    
    [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:object] forKey:@"setting_is_sign_up"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(BOOL)getSignUp
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger value = [defaults integerForKey:@"setting_is_sign_up"];
    return value;
}

+(void)setQuitTime:(NSDate*)object
{
    
    [[NSUserDefaults standardUserDefaults] setValue:[SettingUtils formateDate:object format:DateFormateStringDefault] forKey:@"setting_quit_time"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(NSDate*)getQuitTime
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString * value = [defaults stringForKey:@"setting_quit_time"];
    return [SettingUtils formateDateFromStringToDate:value format:DateFormateStringDefault];
}

+(NSString*)formateDate:(NSDate*)date format:(NSString*)format
{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setAMSymbol:@"AM"];
    [formatter setPMSymbol:@"PM"];
    //    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    //    [formatter setDateFormat:@"MM/dd/yyyy HH:mm"];
    [formatter setDateFormat:format];
    
    NSString* dateStr = [formatter stringFromDate:date];
    
    return dateStr;
}

+(NSDate*)formateDateFromStringToDate:(NSString*)dateStr format:(NSString*)format
{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:format];
    NSDate *date=[formatter dateFromString:dateStr];
    return date;
    
}

@end
